import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:framework/main.dart';
import 'package:module_discover/pages/model/Domain_info_model.dart';
import 'package:module_discover/route/discover_router.gr.dart';
import 'package:module_discover/utils/dis_cons.dart';

@RoutePage()
class FilterSearchPage extends StatelessWidget {
  @PathParam()
  Map<String, Map<String, DomainInfoModel>>? maps;

  List<DomainInfoModel> list = [];

  FilterSearchPage({
    super.key,
    required this.maps,
  });

  @override
  Widget build(BuildContext context) {
    maps?.forEach((parentKey, childMap) {
      childMap.forEach((key, info) {
        if (info.isShow == true) list.add(info);
      });
    });
    return Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          backgroundColor: Colors.blueAccent,
          title: const Text('域名搜索',
              style: TextStyle(color: Colors.white, fontSize: 16)),
          centerTitle: true,
          actions: [
            InkWell(
              onTap: () {
                context.replaceRoute(FilterDomainRoute(chooseBackMaps: maps));
              },
              child: Padding(
                padding: EdgeInsets.symmetric(horizontal: 16),
                child: Icon(
                  Icons.content_paste_search,
                  color: Colors.black,
                  size: 16,
                ),
              ),
            )
          ],
        ),
        body: Padding(
          padding: const EdgeInsets.only(top: 10),
          child: Wrap(
            alignment: WrapAlignment.start,
            spacing: 8.0, // 子组件之间的水平间距
            runSpacing: 8.0, // 行与行之间的垂直间距
            children: list.map((info) {
              return _buildInfoItem(info);
            }).toList(),
          ),
        ));
  }

  Widget _buildInfoItem(DomainInfoModel info) {
    var values = info.key;
    if (info.value.contains(DisCons.SPLIT_S)) {
      values = info.value;
    }
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
      padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
      decoration: BoxDecoration(
        color: JColor.color_f3f3f3,
        borderRadius: BorderRadius.circular(4.0),
      ),
      child: Material(
        color: Colors.transparent,
        child: InkWell(
          onTap: () {},
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              ConstrainedBox(
                constraints: BoxConstraints(maxWidth: 200),
                child: Text('${info.name}:$values',
                    overflow: TextOverflow.ellipsis,
                    maxLines: 1,
                    style: TextStyle(
                        fontSize: 10,
                        decoration: TextDecoration.none,
                        color: Colors.black)),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
